package com.crayon.account.loader;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;

import com.crayon.account.dao.DAOAccount;
import com.crayon.account.dao.DAOTable;
import com.crayon.account.dao.DataBaseManager;
import com.crayon.util.GDB;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;

import org.apache.commons.lang3.StringUtils;

import java.util.LinkedList;
import java.util.List;

public class LoaderSQLTables extends AsyncTaskLoader<List<DAOTable>> {


	public LoaderSQLTables(Context context) {
		super(context);
	}

	@Override
	public List<DAOTable> loadInBackground() {

		DataBaseManager baseManager =DataBaseManager.getHelper(getContext());
		List<DAOTable> list =new LinkedList<DAOTable>();
		try {

			Dao<DAOTable, Integer> daoTable =baseManager.getDAOTable();

			QueryBuilder<DAOTable, Integer> builder = daoTable.queryBuilder();
//			list= builder.orderBy("order",true).query();
			list= builder.query();



		}catch(Exception e ){
			GDB.log(getClass(), "result search err " + e.getMessage());
		}
		GDB.log(getClass(), "result " + (list==null ? 0 : list.size() )+":::");
		return list;
	}

	@Override
	protected void onStartLoading() {
		// TODO Auto-generated method stub
		super.onStartLoading();
		forceLoad();
	}


}


